package com.itheima.demo;

import com.itheima.domain.User;
import com.itheima.uitls.MapperUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class Demo6 {
    public static void main(String[] args)throws Exception {
        InputStream is =Resources.getResourceAsStream("sql.xml");
        //2、构建SqlSessionFactory对象
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);

        SqlSession session1 = factory.openSession();
        User user = session1.selectOne("com.itheima.mapper.UserMapper.findById", 4);
        System.out.println(user);
        session1.close();//清除session1的缓存

        SqlSession session2 = factory.openSession();
        User user2 = session2.selectOne("com.itheima.mapper.UserMapper.findById", 4);
        System.out.println(user2);
        session2.close();
    }
}
